package com.lry.jvm.jnative;


import java.util.HashMap;
import java.util.Map;

public class Registry {
    private static Map<String, NativeMethod> registry = new HashMap<>();

    public static void register(String className,String methodName,String methodDescriptor,NativeMethod method){
        String key = getKey(className,methodName,methodDescriptor);
        registry.put(key,method);
    }

    public static NativeMethod findNativeMethod(String className,String methodName,String methodDescriptor){
        String key = getKey(className,methodName,methodDescriptor);
        NativeMethod method = registry.get(key);
        if(null!=method){
            return method;
        }

//        if(methodDescriptor.equals("()V") && methodName.equals("registerNatives")){
//            return emptyNativeMethod;
//        }
        return null;
    }

    private static String getKey(String className,String methodName,String methodDescriptor){
        String key = className+"~"+methodName+"~"+methodDescriptor;
        return key;
    }
}
